/**
  ******************************************************************************
  * @file    bsp_can.h
  * @author  Iron
  * @date    2018-07-17
  * @version v1.0
  * @brief   CAN comunicaiton header file
  */

#ifndef __BSP_CAN_H
#define __BSP_CAN_H

#ifdef __cplusplus
extern "C" {
#endif

/* includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"

/* exported types ------------------------------------------------------------*/
typedef CAN_RxHeaderTypeDef  can_rx_header_t;
typedef CAN_TxHeaderTypeDef  can_tx_header_t;

typedef struct
{
    can_rx_header_t header;
    uint8_t data[8];
} can_msg_t;

/* exported constants --------------------------------------------------------*/
/* exported macro ------------------------------------------------------------*/
#define BSP_CAN_FAIL                    0
#define BSP_CAN_OK                      1
#define BSP_CAN_RX_OVERFLOW     2

/* exported functions ------------------------------------------------------- */
int32_t bsp_can_send_msg(can_tx_header_t *header, uint8_t data[], uint32_t *tx_mail_bpx);
int32_t bsp_can_recv_msg(can_msg_t *msg, uint32_t timeout);
int32_t bsp_can_init(void);

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* __BSP_CAN_H */

/******************* (C)COPYRIGHT 2018 ***** END OF FILE *********************/
